<?php
class DivisionsController extends AppController {

	var $name = 'Divisions';
	var $helpers = array('Html', 'Form', 'Authake.Authak3');
	
	var $uses = array('Division');
	/*
	 * устанавливаем методом id факультетов в cookies для того чтобы не лезли в другие деканаты
	 */
	function setdivision($id) {
	/* 	$this->loadModel('Facultet');
		
		// обнуляем массив id факультетов 
		$facultet_ids = array();
		$facultets = $this->Facultet->find('all', array('recursive' => -1, 'fileds' => array('Facultet.id')));
		// получили список id всех факультетов  
		foreach ($facultets as $facultet):
			array_push($facultet_ids, $facultet['Facultet']['id']);
		endforeach; */
		
	//	debug($facultets);
		//$settings = $this->Session->read('LogsSettings');
		//debug($this);
		$this->loadModel('Log');
		$settings = $this->Session->read('LogsSettings');
		debug($settings);
		$ll =  $this->params['url'];
		debug($ll);
	//	$newlog = array('Log' => array('login' => ))
	}
	
	function loadhostelstudents() {
		if (!empty($this->data)){
			$this->loadModel('HostelsStudent');
			$csvfile = fopen($this->data["Division"]["csvfile"]["tmp_name"],"r");
			while(!(feof($csvfile))) {
				$line = fgetcsv($csvfile, 10000, ";");
				if ($line) {
					$student_id = iconv('Windows-1251', 'UTF-8',trim($line[4]));
					$hostel_id = iconv('Windows-1251', 'UTF-8',trim($line[9]));
					$room = iconv('Windows-1251', 'UTF-8',trim($line[10]));
					$this->HostelsStudent->create();
					$new_hostelstudent = array('HostelsStudent' => array('hostel_id' => $hostel_id,
																		'student_id' => $student_id,
																		'room' => $room));
					$this->HostelsStudent->save($new_hostelstudent);
				}
			}
		}
	}
}
?>